package ch.ethz.eai.webservice;

import java.rmi.RemoteException;

import org.apache.axis2.AxisFault;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;

import ch.ethz.eai.webservice.OurWebServiceStub.GetProposalsByAddress;
import ch.ethz.eai.webservice.OurWebServiceStub.GetProposalsByAddressResponse;
import ch.ethz.eai.webservice.OurWebServiceStub.GetProposalsByCoordinates;
import ch.ethz.eai.webservice.OurWebServiceStub.GetProposalsByCoordinatesResponse;
import ch.ethz.eai.webservice.OurWebServiceStub.ResponseMessage;
import ch.ethz.eai.webservice.OurWebServiceStub.SetWeatherStatusByAddress;
import ch.ethz.eai.webservice.OurWebServiceStub.SetWeatherStatusByAddressResponse;
import ch.ethz.eai.webservice.OurWebServiceStub.SetWeatherStatusByCoordinates;
import ch.ethz.eai.webservice.OurWebServiceStub.SetWeatherStatusByCoordinatesResponse;



public class ServiceProxy {

	
	public static ResponseMessage getProposalsByAddress(String address_){
		try{
			//parameters are path to WEB-INF folder and path to axis2.xml file
			ConfigurationContext cc = ConfigurationContextFactory.
					createConfigurationContextFromFileSystem("D:\\My Doc\\master\\Enterprise Application Integration\\Exercises\\workspace\\TestClient\\WebContent\\WEB-INF",
							"D:\\My Doc\\master\\Enterprise Application Integration"
							+ "\\Exercises\\workspace\\TestClient\\WebContent\\WEB-INF\\conf\\axis2.xml");
			OurWebServiceStub stub = new OurWebServiceStub(cc);
			GetProposalsByAddress address = new GetProposalsByAddress();
			address.setLocation(address_);
			
			GetProposalsByAddressResponse wrappedObj = stub.getProposalsByAddress(address);
			if(wrappedObj != null) return wrappedObj.get_return();
		} catch(AxisFault e){
			e.printStackTrace();
		}catch (RemoteException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static ResponseMessage getProposalsByGeoLocation(String X, String Y){
		try{
			//parameters are path to WEB-INF folder and path to axis2.xml file
			ConfigurationContext cc = ConfigurationContextFactory.
					createConfigurationContextFromFileSystem("D:\\My Doc\\master\\Enterprise Application Integration\\Exercises\\workspace\\TestClient\\WebContent\\WEB-INF", 
							"D:\\My Doc\\master\\Enterprise Application Integration"
							+ "\\Exercises\\workspace\\TestClient\\WebContent\\WEB-INF\\conf\\axis2.xml");
			OurWebServiceStub stub = new OurWebServiceStub(cc);			
			GetProposalsByCoordinates getProposalsByCoordinates2 = new GetProposalsByCoordinates();
			getProposalsByCoordinates2.setLatitude(Double.parseDouble(X));
			getProposalsByCoordinates2.setLongtitude(Double.parseDouble(Y));
			
			GetProposalsByCoordinatesResponse wrappedObj = stub.getProposalsByCoordinates(getProposalsByCoordinates2);
			if(wrappedObj != null) return wrappedObj.get_return();
		} catch(AxisFault e){
			e.printStackTrace();
		}catch (RemoteException e) {
			e.printStackTrace();
		}
		return null;
	}
	public static ResponseMessage setWeatherStatusByAddress(String address, String status){
		System.out.println("Giving feedback by address");
		System.out.println("The status given: " + status);
		try{
			//parameters are path to WEB-INF folder and path to axis2.xml file
			ConfigurationContext cc = ConfigurationContextFactory.
					createConfigurationContextFromFileSystem("D:\\My Doc\\master\\Enterprise Application Integration\\Exercises\\workspace\\TestClient\\WebContent\\WEB_INF", 
							"D:\\My Doc\\master\\Enterprise Application Integration"
							+ "\\Exercises\\workspace\\TestClient\\WebContent\\WEB-INF\\conf\\axis2.xml");
			OurWebServiceStub stub = new OurWebServiceStub(cc);			
			SetWeatherStatusByAddress setWeatherStatusByAddress4 = new SetWeatherStatusByAddress();
			setWeatherStatusByAddress4.setLocation(address);
			setWeatherStatusByAddress4.setStype(status);
			SetWeatherStatusByAddressResponse wrappedObj = stub.setWeatherStatusByAddress(setWeatherStatusByAddress4);
			if(wrappedObj != null) return wrappedObj.get_return();
		
		} catch(AxisFault e){
			e.printStackTrace();
		}catch (RemoteException e) {
			e.printStackTrace();
		}
		return null;
	}
	public static ResponseMessage setWeatherStatusByCoordinates(String X, String Y, String status){
		System.out.println("Giving feedback by coordinates");
		try{
			//parameters are path to WEB-INF folder and path to axis2.xml file
			ConfigurationContext cc = ConfigurationContextFactory.
					createConfigurationContextFromFileSystem("D:\\My Doc\\master\\Enterprise Application Integration\\Exercises\\workspace\\TestClient\\WebContent\\WEB-INF", 
							"D:\\My Doc\\master\\Enterprise Application Integration"
							+ "\\Exercises\\workspace\\TestClient\\WebContent\\WEB-INF\\conf\\axis2.xml");
			OurWebServiceStub stub = new OurWebServiceStub(cc);			
			SetWeatherStatusByCoordinates setWeatherStatusByCoordinates0 = new SetWeatherStatusByCoordinates();
			setWeatherStatusByCoordinates0.setLatitude(Double.parseDouble(X));
			setWeatherStatusByCoordinates0.setLongtitude(Double.parseDouble(Y));
			setWeatherStatusByCoordinates0.setStype(status);
			SetWeatherStatusByCoordinatesResponse wrappedObj = stub.setWeatherStatusByCoordinates(setWeatherStatusByCoordinates0);
			if(wrappedObj != null) return wrappedObj.get_return();`

		} catch(AxisFault e){
			e.printStackTrace();
		}catch (RemoteException e) {
			e.printStackTrace();
		}
		return null;
	}
}
	
